package mysql

import "gorm.io/gorm"

type Good struct {
	gorm.Model
	UserId    int     `gorm:"type:int;not null;comment:'用户Id'"`
	GoodTitle string  `gorm:"type:varchar(50);not null;comment:'商品标题'"`
	GoodStock int     `gorm:"type:int;not null;comment:'商品库存'"`
	GoodImage string  `gorm:"type:varchar(255);not null;comment:'图片'"`
	GoodPrice float64 `gorm:"type:double(10,2);not null;comment:'商品价格'"`
	GoodLike  int     `gorm:"type:int;not null;comment:'点赞'"`
}

func (g *Good) GetGood(page, pageSize int) (list []Good, err2 error) {
	err2 = DB.Order("good_like desc").Offset((page - 1) * pageSize).Limit(pageSize).Find(&list).Error
	return
}

func (g *Good) ShowGood(id int) (list []Good, err2 error) {
	err2 = DB.Where("id = ?", id).Limit(1).Find(&list).Error
	return
}

func (g *Good) GetOrderG(id int) error {
	return DB.Where("id = ?", id).Limit(1).Find(&g).Error
}
